package com.ujson.chat.client.handler;

import com.ujson.chat.common.codec.ProtoDecoder;
import com.ujson.chat.common.codec.ProtoEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <h3>ujson-parent</h3>
 * <p></p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-28 21:34
 */
@Slf4j
@Service
public class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {
//    @Autowired
//    private ProtoEncoder protoEncoder;
//
//    @Autowired
//    private ProtoDecoder protoDecoder;

    @Autowired
    private LoginResponseHandler loginResponseHandler;

    @Autowired
    private LogoutResponseHandler logoutResponseHandler;

    @Autowired
    private MessageResponseHandler messageResponseHandler;

    @Autowired
    private HeartbeatResponseHandler heartbeatResponseHandler;

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        channel.pipeline()
                .addLast("decoder", new ProtoDecoder())
                .addLast("encoder", new ProtoEncoder())
                .addLast(loginResponseHandler)
                .addLast(messageResponseHandler)
                .addLast(logoutResponseHandler)
        ;
    }
}
